﻿using System;

namespace _11.FindIndexOfGivenElementInSortedArray
{
    class FindIndexOfGivenElementInSortedArray
    {
        static void Main()
        {
            int[] arr = { 1, 3, 5, 7, 9, 11, 13, 15, 17 };
            int element = 17;
            int start = 0;
            int end = arr.Length-1;
            int mid = 0;
            bool match = false;
            for (int i = 0; i < arr.Length; i++)
            {
                mid = start + (end-start) / 2;
                if (arr[mid]==element)
                {
                   match = true;
                }
                else
                {
                    if (element<arr[mid])
                    {
                        end = mid - 1;
                    }
                    else
                    {
                        start = mid + 1;
                    }
                }
            }
            Console.WriteLine("The index of element with value {0} is:{1}", element, mid);
            if (match==false)
            {
                Console.WriteLine("There is no element with value {0} is:{1}",element,mid);
            }
        }
    }
}
